// 表单存储的是value 因为回显的时候也回显的是value 所以表单要存value 但是上传给后端的时候要用title
import { getStore } from '@/libs/storage';
import Cookies from 'js-cookie';

function getTitleByValue(list, value) {
    if(list.length === 0){
        return '';
    }
    for (let i = 0; i < list.length; i++) {
        if (list[i].value === value) {
            return list[i].title;
        }
    }
    return value ?? '';
}

async function excelExport(ids) {
    let body = ids ? 'ids=' + ids.join(',') : '';

    let baseApi = config.baseApi;
    let accessToken = getStore('accessToken');
    let res = await fetch(baseApi + '/HardshipSupport/exportBatch', {
        method: 'post',
        headers: {
            accessToken: accessToken,
            'Content-Type': 'application/x-www-form-urlencoded',
            'Tablename': Cookies.get("tableName")
        },
        body
    });
    return await res.blob();
}

export { getTitleByValue, excelExport };
